package com.orangelife.service.base;

import java.util.Map;

import javax.servlet.http.HttpSession;

import com.orangelife.service.base.dict.impl.AbstractDictionary;

/**
 * session 上下文
 * <p>
 * 
 * TODO 因为已有的Session处理存在问题，所有的关联登陆对象并放置统一个对象内，再下一个版本将要统一处理掉。
 * 
 * @author lance
 * 
 *         2012-5-7
 */
public class SessionContext extends AbstractDictionary<String, Object> {

	private static final String KEY_SESSIONCONTEXT = "session.SessionContext";

	public static SessionContext getContext(HttpSession session) {
		synchronized (session) {
			SessionContext sessionContext = (SessionContext) session
					.getAttribute(KEY_SESSIONCONTEXT);
			if (sessionContext == null) {
				sessionContext = new SessionContext();
				session.setAttribute(KEY_SESSIONCONTEXT, sessionContext);
			}
			return sessionContext;
		}
	}

	public static SessionContext getContext(Map<String, Object> strutsSession) {
		SessionContext sessionContext = (SessionContext) strutsSession
				.get(KEY_SESSIONCONTEXT);
		if (sessionContext == null) {
			sessionContext = new SessionContext();
			strutsSession.put(KEY_SESSIONCONTEXT, sessionContext);
		}
		return sessionContext;

	}

}
